/*
 * File:   EggHolder.h
 * Author: jcrada
 *
 * Created on 14 December 2010, 1:10 PM
 */

#ifndef ECB_EGGHOLDER_H
#define	ECB_EGGHOLDER_H

#include "ecb/base/Problem.h"
#include <cmath>
namespace ecb {

    class EggHolder : public Problem {
    public:
        //Source: http://www.maths.uq.edu.au/CEToolBox/

        EggHolder(const std::string& id = "EggHolder", const std::string& name = "EggHolder",
                int dimensions = 0, scalar minimum = -512, scalar maximum = 512,
                bool minimization = true) :
        Problem(id, name, dimensions, minimum, maximum, minimization) { }
        scalar f(const std::vector<scalar>& x) {
            scalar result = 0.0;
            for (size_t i = 0; i < x.size() - 1; i++) {
                result += (-(x[i + 1] + 47)
                        * std::sin(std::sqrt(std::fabs(x[i + 1] + x[i] / 2 + 47)))
                        + std::sin(std::sqrt(std::fabs(x[i] - (x[i + 1] + 47))))
                        *(-x[i]));
            }
            return result;
        }
    };
}


#endif	/* ECB_EGGHOLDER_H */

